package at.fhooe.mc.sn.gui;

import java.awt.Font;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import at.fhooe.mc.sn.SmartSensorJavaClient;
import java.awt.BorderLayout;


public class GUI {

	private JFrame frame;
	private SmartSensorJavaClient controller;
	private JPanel panel;


	/**
	 * Create the application.
	 */
	public GUI(SmartSensorJavaClient controller) {
		this.controller = controller;
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	@SuppressWarnings("serial")
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 854, 743);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JTree tree = new JTree();
		tree.setBounds(0, 0, 141, 705);
		tree.setModel(new DefaultTreeModel(
			new DefaultMutableTreeNode("SmartSensor") {
				{
					add(new DefaultMutableTreeNode("Accelerometer"));
					add(new DefaultMutableTreeNode("Temperature"));
				}
			}
		));
		frame.getContentPane().add(tree);
		
		panel = new JPanel();
		panel.setBounds(148, 0, 690, 705);
		frame.getContentPane().add(panel);
		panel.setLayout(new BorderLayout(0, 0));
		
		JMenuBar menuBar = new JMenuBar();
		frame.setJMenuBar(menuBar);
		
		JMenu mnConnect = new JMenu("Arduino");
		menuBar.add(mnConnect);
		
		JMenuItem mntmReconnect = new JMenuItem("Connect");
		mnConnect.add(mntmReconnect);
		mntmReconnect.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
		
		JMenuItem mntmSerialMonitor = new JMenuItem("Serial Monitor");
		mntmSerialMonitor.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
		mnConnect.add(mntmSerialMonitor);
		
		JMenuItem mntmReset = new JMenuItem("Reset");
		mntmReset.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK));
		mnConnect.add(mntmReset);
		
		JMenuItem mntmExit = new JMenuItem("Exit");
		mntmExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));
		mnConnect.add(mntmExit);
		
		mntmExit.addActionListener(controller);
		mntmReconnect.addActionListener(controller);
		mntmReset.addActionListener(controller);
		mntmSerialMonitor.addActionListener(controller);
		tree.addTreeSelectionListener(controller);
	}
	
	public JFrame getFrame() {
		return frame;
	}
	
	public JPanel getPanel() {
		return panel;
	}
}
